import Vue from 'vue'
import VueRouter from 'vue-router'
//引入封装好的仓库
import store from '../store'
Vue.use(VueRouter)
export const indexRoutes = [

  {
    path: '/menu',
    component: () => import('../views/menu/menu.vue'),
    meta: {
      name: '系统管理'
    }
  },
  {
    path: '/role',
    component: () => import('../views/role/role.vue'),
    meta: {
      name: '角色管理'
    }
  },
  {
    path: '/admin',
    component: () => import('../views/admin/admin.vue'),
    meta: {
      name: '管理员管理'
    }
  },{
    path: '/spec',
    component: () => import('../views/spec/spec.vue'),
    meta: {
      name: '商品分类'
    },
  },{
    path: '/specs',
    component: () => import('../views/goodsspecs/goodsspecs.vue'),
    meta: {
      name: '商品规格'
    },
  },{
    path: '/spgl',
    component: () => import('../views/spgl/spgl.vue'),
    meta: {
      name: '商品管理'
    },
  },
  {
    path: '/ms',
    component: () => import('../views/ms/ms.vue'),
    meta: {
      name: '商品秒杀'
    },
  }
]

const routes = [{
    path: '/login',
    component: () => import('../pages/login.vue')
  },
  {
    path: '/index',
    component: () => import('../pages/index.vue'),
    children: [
      ...indexRoutes,
      {
        path: '/home',
        component: () => import('../views/home.vue')
      },
      {
        path: '',
        redirect: '/home'
      }
    ]
  },
  {
    path: '*',
    redirect: '/index'
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// //封装全局登录拦截
// router.beforeEach((to,from,next)=>{
//   //如果去的是登录就放行
//   if(to.path=='/login'){
//     next()
//     return
//   }
//   //如果有登录状态我们就next
//   if(store.getters.getUser){
//     next()
//     return
//   }
//   //以上条件都不符合
//   next('/login')
// })

export default router